package com.edu.juc.lock;

import java.util.concurrent.*;

public class EightLocksTest {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        CompletableFuture<Void> future1 = CompletableFuture.runAsync(() -> {
            try {
                Phone.call();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, threadPool);
        CompletableFuture<Void> future2 = CompletableFuture.runAsync(() -> {

            Phone phone = new Phone();
            System.out.println(phone);

        }, threadPool);

        try {
            future2.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }


        threadPool.shutdown();
    }
}

class Phone {
    public static synchronized void call() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        System.out.println("call()...");
    }

    public Phone() {
        System.out.println("Phone()...");
    }
}
